package com.liqiye.paymanager.service.common.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liqiye.paymanager.bean.order.CreateOrderRequest;
import com.liqiye.paymanager.constant.OrderStatus;
import com.liqiye.paymanager.entity.Order;
import com.liqiye.paymanager.mapper.OrderMapper;
import com.liqiye.paymanager.service.common.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public List<Order> selectAll() {
        return orderMapper.selectAll();
    }

    public void insert(Order order){
        orderMapper.insert(order);
    }

    public void create(CreateOrderRequest req){
        Order order = new Order();
        BeanUtil.copyProperties(req, order, true);
        order.setStatus(OrderStatus.CREATED.name());
        orderMapper.insert(order);
    }

    public void deleteById(String id){
        orderMapper.deleteById(id);
    }

}
